package aliyunCli

import (
	"fmt"
	"tushare/conf"

	ecs "github.com/aliyun/alibaba-cloud-sdk-go/services/ecs"
)

type DescribeInstances struct{}

func (di DescribeInstances) DescribeInstances(instanceId string) string {
	client, err := ecs.NewClientWithAccessKey("cn-hangzhou", conf.AccessKeyID, conf.AccessKeySecret)

	request := ecs.CreateDescribeInstancesRequest()
	request.Scheme = "https"

	request.InstanceIds = fmt.Sprintf("['%s']", instanceId)

	response, err := client.DescribeInstances(request)
	if err != nil {
		fmt.Print(err.Error())
	}

	return response.Instances.Instance[0].PublicIpAddress.IpAddress[0]
}
